package com.example.controller.comment;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.common.Result;
import com.example.dto.CommentDTO;
import com.example.dto.CommentLikeDTO;
import com.example.dto.CommentQueryDTO;
import com.example.service.CommentService;
import com.example.vo.CommentVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 博客评论表 前端控制器
 * </p>
 *
 * @author wuyunbin
 * @since 2024-10-20
 */
@RestController
@RequestMapping("/comments")
public class CommentController {

    @Resource
    private CommentService commentService;

    /**
     * 添加评论
     */
    @PostMapping("/add")
    public Result<Long> addComment(@RequestBody CommentDTO commentDTO) {
        Long commentId = commentService.addComment(commentDTO);
        return Result.success(commentId);
    }

    /**
     * 获取文章评论列表
     */
    @GetMapping("/list")
    public Result<IPage<CommentVO>> getComments(CommentQueryDTO queryDTO) {
        IPage<CommentVO> commentPage = commentService.getCommentsByArticleId(queryDTO);
        return Result.success(commentPage);
    }

    /**
     * 点赞评论
     */
    @PostMapping("/like")
    public Result<Boolean> likeComment(@RequestBody CommentLikeDTO likeDTO) {
        boolean success = commentService.likeComment(likeDTO);
        return Result.success(success);
    }
} 